package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.KnowledgeSportMapper;
import com.itheima.pojo.KnowledgeSport;
import com.itheima.service.KnowledgeSportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = KnowledgeSportService.class)
@Transactional
public class KnowledgeSportServiceImpl implements KnowledgeSportService {
    @Autowired
    private KnowledgeSportMapper knowledgeSportMapper;

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<KnowledgeSport> knowledgeSports = knowledgeSportMapper.selectByCondition(queryString);
        long total = knowledgeSports.getTotal();
        List<KnowledgeSport> result = knowledgeSports.getResult();
        return new PageResult(total,result);
    }

    @Override
    public void add(KnowledgeSport knowledgeSport) {
        knowledgeSportMapper.add(knowledgeSport);
    }

    @Override
    public void edit(KnowledgeSport knowledgeSport) {
        knowledgeSportMapper.edit(knowledgeSport);
    }

    @Override
    public void delete(Integer id) {
        knowledgeSportMapper.delete(id);
    }

    @Override
    public List<KnowledgeSport> findAll() {
        return knowledgeSportMapper.findAll();
    }
}
